package control;
import java.math.BigDecimal;
import java.util.Comparator;

import data.Constant;
import data.TimeStock;

public class AmountBatCompare implements Comparator<TimeStock> {
	public int compare(TimeStock ts1, TimeStock ts2) {
		BigDecimal amountBat1 = new BigDecimal(0);
		BigDecimal amountBat2 = new BigDecimal(0);
		if(ts1.getAmount()!=null&&ts1.getLastStock().getAmount()!=null){
			if(ts1.getLastStock().getAmount().compareTo(Constant.ZERO)>0)
				amountBat1 =ts1.getAmount().divide(ts1.getLastStock().getAmount(),2,BigDecimal.ROUND_HALF_UP);
		}
		if(ts2.getAmount()!=null&&ts2.getLastStock().getAmount()!=null){
			if(ts2.getLastStock().getAmount().compareTo(Constant.ZERO)>0)
				amountBat2 =ts2.getAmount().divide(ts2.getLastStock().getAmount(),2,BigDecimal.ROUND_HALF_UP);
		}
		return amountBat2.compareTo(amountBat1);
	}
}
